#ifndef SJRPASSWORD_COMM_FORMAT_HPP
#define SJRPASSWORD_COMM_FORMAT_HPP

SJR_NAMESPACE_BEGIN

class EpubFormat final {
public:
  constexpr static int BufferSize = 2048;

  template<class... Args>
  static std::string format(std::string const &format, Args... args) {
    return EpubFormat::instance().toFormat(format, args...);
  }

private:
  char mBuffer[BufferSize];
  EpubMutex mSync;

  EpubFormat() : mBuffer(), mSync() {}

  static EpubFormat &instance() {
    static EpubFormat *obj = nullptr;
    if (obj == nullptr)
      obj = new EpubFormat();
    return (*obj);
  }

  template<class... Args>
  std::string toFormat(std::string const &format, Args... args) {
    EpubUniqueLock lock(mSync);
    snprintf(mBuffer, sizeof(mBuffer), format.c_str(), args...);
    return mBuffer;
  }
};

SJR_NAMESPACE_END

#endif//SJRPASSWORD_COMM_FORMAT_HPP
